package com.jvtd.demo.app;

import android.net.Uri;
import android.text.TextUtils;

import com.jvtd.app.JvtdApplication;
import com.jvtd.demo.im.listener.MyConnectionStatusListener;
import com.jvtd.demo.im.listener.MyConversationClickListener;
import com.jvtd.demo.im.listener.MyConversationListBehaviorListener;
import com.jvtd.jpush.JvtdPush;
import com.jvtd.rong_im.JvtdRongIM;

import io.rong.imkit.model.GroupUserInfo;
import io.rong.imlib.model.Group;
import io.rong.imlib.model.UserInfo;

public class MyApp extends JvtdApplication
{
  @Override
  public void onCreate()
  {
    super.onCreate();
    JvtdPush.getInstance(this).init().isDevelopment().setAlias("15611678120");

    JvtdRongIM.getInstance(this).init("qd46yzrfqifkf").checkManifest()
            .setUserInfoProvider(userId ->
            {
              if (TextUtils.equals(userId, "user001"))
                JvtdRongIM.getInstance(this).refreshUserInfoCache(new UserInfo(userId, "用户001", Uri.parse("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541064713193&di=03736421023255ccddd3ac44c70d5635&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201404%2F12%2F20140412161909_wyL25.thumb.600_0.jpeg")));
              else if (TextUtils.equals(userId, "user002"))
                JvtdRongIM.getInstance(this).refreshUserInfoCache(new UserInfo(userId, "用户002", Uri.parse("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541064758522&di=22c05eba533a6958d44089803afe95a0&imgtype=0&src=http%3A%2F%2Fdream.ph.126.net%2F32f28tSp9hnXdOcjHjJq0A%3D%3D%2F3517337699032200")));
            })
            .setGroupUserInfoProvider((groupId, userId) ->
            {
              if (TextUtils.equals(groupId, "group001"))
              {
                if (TextUtils.equals(userId, "user001"))
                  JvtdRongIM.getInstance(this).refreshGroupUserInfoCache(new GroupUserInfo(groupId, userId, "群组001用户001"));
                else if (TextUtils.equals(userId, "user002"))
                  JvtdRongIM.getInstance(this).refreshGroupUserInfoCache(new GroupUserInfo(groupId, userId, "群组001用户002"));
              } else if (TextUtils.equals(groupId, "group002"))
              {
                if (TextUtils.equals(userId, "user001"))
                  JvtdRongIM.getInstance(this).refreshGroupUserInfoCache(new GroupUserInfo(groupId, userId, "群组002用户001"));
                else if (TextUtils.equals(userId, "user002"))
                  JvtdRongIM.getInstance(this).refreshGroupUserInfoCache(new GroupUserInfo(groupId, userId, "群组002用户002"));
              }
            })
            .setGroupInfoProvider(groupId ->
            {
              if (TextUtils.equals(groupId, "group001"))
                JvtdRongIM.getInstance(this).refreshGroupInfoCache(new Group(groupId, "群组001", Uri.parse("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541659495&di=c7c60ed17a8b723d366f4c730552a8bd&imgtype=jpg&er=1&src=http%3A%2F%2Ffmn.rrimg.com%2Ffmn057%2Fxiaozhan%2F20121221%2F2035%2Foriginal_20KZ_484600000a2d1190.jpg")));
              else if (TextUtils.equals(groupId, "group002"))
                JvtdRongIM.getInstance(this).refreshGroupInfoCache(new Group(groupId, "群组002", Uri.parse("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541064773455&di=d914325c93ae53b49d091016db2adee7&imgtype=0&src=http%3A%2F%2Ffmn.rrimg.com%2Ffmn061%2Fxiaozhan%2F20121221%2F2035%2Foriginal_drQo_486500000a311190.jpg")));
            })
            //显示新消息提醒
            .enableNewComingMessageIcon()
            //显示未读消息数目
            .enableUnreadMessageIcon()
            .setConnectionStatusListener(new MyConnectionStatusListener(getApplicationContext()))
            .setConversationListBehaviorListener(new MyConversationListBehaviorListener(getApplicationContext()))
            .setConversationClickListener(new MyConversationClickListener(getApplicationContext()));
  }

  @Override
  public void configGlobalInit()
  {

  }
}
